package com.ruoyi.order.config;

import com.alibaba.excel.EasyExcel;
import com.ruoyi.common.core.utils.SpringUtils;
import com.ruoyi.order.service.ITbOrderService;
import com.ruoyi.order.vo.OrderVo;

import java.io.File;
import java.util.List;
import java.util.concurrent.Callable;

public class ExportCallable implements Callable<String> {

    private long storyId;
    private String year;
    private String month;


    public ExportCallable(long storyId, String year, String month) {
        this.storyId = storyId;
        this.year=year;
        this.month = month;
    }

    @Override
    public String call() throws Exception {
        ITbOrderService orderService = SpringUtils.getBean(ITbOrderService.class);


        List<OrderVo> orderList = orderService.selectList(year,month,storyId);
        String file="D:\\JavaTest\\"+storyId;
        File newFile = new File(file);
        if(!newFile.exists()){
            newFile.mkdirs();
        }
        String fileName=file+"\\"+month+".xlsx";
        File xlsxFile = new File(fileName);
        EasyExcel.write(fileName, OrderVo.class).sheet("订单文档").doWrite(orderList);


        System.out.println("线程"+month+"开始");
        Thread.sleep(5000);
        System.out.println("线程"+month+"结束");

        return fileName;



    }
}
